package com.googlecode.jgae;

import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;

/**
 * @author Denis Migol
 */
public class GaeJUnit4ClassRunner extends BlockJUnit4ClassRunner {
    private static final LocalServiceTestHelper helper = new LocalServiceTestHelper(
            new LocalDatastoreServiceTestConfig());

    public GaeJUnit4ClassRunner(Class<?> clazz) throws InitializationError {
        super(clazz);
    }

    @Override
    public void run(RunNotifier notifier) {
        try {
            helper.setUp();
            super.run(notifier);
        } finally {
            try {
                helper.tearDown();
            } catch (Exception ignored) {
            }
        }
    }
}
